﻿Imports System
Imports System.IO
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Data.Common

Module ZoneDao

    Public Function findZones(ByVal zone As String, ByVal projectId As String) As DataTable
        Dim dtResult As New DataTable
        Dim paramList As New Hashtable()

        Dim SQL As String = "SELECT * FROM eqam_zone WHERE 1=1 "

        If (zone IsNot Nothing And zone <> "") Then
            SQL = SQL & " AND ZONE = @ZONE"
            paramList.Add("@ZONE", zone)
        End If

        If (projectId IsNot Nothing And projectId <> "") Then
            SQL = SQL & " AND PROJECT_ID = @PROJECT_ID"
            paramList.Add("@PROJECT_ID", projectId)
        End If

        SQL = SQL & " ORDER BY ZONE "

        Return LoadData(SQL, paramList)
    End Function

    Public Function getZoneSeq(ByVal zone As String, ByVal projectId As String) As Integer
        Dim dtResult As New DataTable

        Dim index As Integer = 1
        dtResult = findZones(zone, projectId)

        If dtResult.Rows.Count > 0 Then
            index = dtResult.Rows(0).Item("SEQ")        
        End If

        If (index = 0) Then
            index = 1
        End If

        Return index
    End Function
End Module
